//
// SoapTrace.Net - A soap message monitoring utility. 
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)

using NUnit.Framework;
using SoapTrace.Core.Formatters;
using SoapTrace.Tests.Utils;
using System;

namespace SoapTrace.Tests.FormatterManagement
{
	/// <summary>
	/// Tests the <see cref="MessageFormatterManager"/>'s loading
	/// of one custom message formatter.
	/// </summary>
	[ TestFixture ]
	public class OneCustomFormatterTestFixture
	{
		MessageFormatterManager Manager;
		
		/// <summary>
		/// Initialises each test.
		/// </summary>
		[ SetUp ]
		public void Init( )
		{
			MessageFormatterEntryCollection Entries = new MessageFormatterEntryCollection( );
			MessageFormatterEntry Entry = new MessageFormatterEntry( );
			Entry.FullTypeName = "SoapTrace.Tests.Utils.MockMessageFormatter, SoapTrace.Tests";
			Entries.Add( Entry );
			
			Manager = new MessageFormatterManager( Entries );
		}
		
		/// <summary>
		/// Checks that one custom message formatter has been
		/// set up.
		/// </summary>
		[ Test ]
		public void FormatterCount( )
		{
			Assert.AreEqual( 1, Manager.GetCustomFormatterNames( ).Length, "Expecting one custom formatter." );
		}
		
		/// <summary>
		/// Check that the current formatter is a simple message formatter.
		/// </summary>
		[ Test ]
		public void CurrentFormatter( )
		{
			Assert.AreEqual( typeof( SimpleMessageFormatter ), 
			                Manager.CurrentFormatter.GetType( ),
			                "Expecting simple message formatter type as current formatter." );
		}
		
		/// <summary>
		/// Check that the custom formatter has been loaded.
		/// </summary>
		[ Test ]
		public void CustomFormatterName( )
		{
			string[ ] Names = Manager.GetCustomFormatterNames( );
			
			Assert.AreEqual( MockMessageFormatter.FormatterName, 
			                Names[ 0 ],
			                "Expecting mock message formatter." );
		}
		
		/// <summary>
		/// Select the custom formatter.
		/// </summary>
		[ Test ]
		public void CustomFormatterSelected( )
		{
			Manager.SelectCustomFormatter( MockMessageFormatter.FormatterName );
			Assert.AreEqual( typeof( MockMessageFormatter ), 
			                Manager.CurrentFormatter.GetType( ),
			                "Expecting mock message formatter type as current formatter." );
		}
		
		/// <summary>
		/// Check that the current formatter is changed back to
		/// the simple message formatter.
		/// </summary>
		[ Test ]
		public void CurrentFormatterChanged( )
		{
			Manager.SelectCustomFormatter( MockMessageFormatter.FormatterName );
			Manager.DeselectAllCustomFormatters( );
			
			Assert.AreEqual( typeof( SimpleMessageFormatter ),
			                Manager.CurrentFormatter.GetType( ),
			                "Expecting simple message formatter type as current formatter." );
		}
	}
}
